package com.xuehu.cloud.controller;

import com.xuehu.cloud.service.impl.PaymentServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author guoweia@cslc.com.cn
 * @createTime 2020/12/1 16:15
 * @description
 */
@RestController
@Slf4j
public class PaymentController {
    @Resource
    private PaymentServiceImpl paymentService;

    @Value("${server.port}")
    private String serverPort;

    @GetMapping("/pay/hystrix/ok/{id}")
    public String paymentOk(@PathVariable("id") Long id) {
        String result = paymentService.paymentOk(id);
        log.info("*******result:" + result + "*******");
        return  "端口：" + serverPort + ",结果：" + result;
    }

    @GetMapping("/pay/hystrix/timeout/{id}")
    public String paymentTimeout(@PathVariable("id") Long id) {
        String result = paymentService.paymentTimeout(id);
        log.info("*******result:" + result + "*******");
        return  "端口：" + serverPort + ",结果：" + result;
    }

    @GetMapping("/pay/hystrix/circuitbreaker/{id}")
    public String paymentCircuitBreaker(@PathVariable("id")Long id) {
        String result = paymentService.paymentCircuitBreaker(id);
        log.info("*******paymentCircuitBreaker==result:" + result + "*******");
        return  "端口：" + serverPort + ",结果：" + result;
    }
}
